package org.discala.samples.complex.recipegenerator

import org.discala.samples.complex.domain.MealType.MealType
import org.discala.samples.complex.domain.Recipe

/**
 * @author Chris Turner
 */
trait RecipeGeneratorComponent {

  this : AnyRef { val factory: () => IngredientFactory
                  val methodSelector: () => MethodSelector } =>

  val recipeGenerator: () => RecipeGenerator

  class RandomContentRecipeGenerator extends RecipeGenerator {

    def createRecipe(mealType: MealType, ingredientCount: Int) = {
      val recipe = new Recipe(mealType)
      while ( recipe.ingredientCount < ingredientCount ) {
        recipe << factory().ingredient
      }
      recipe.preparationMethod = methodSelector().selectMethod(mealType)
      recipe
    }
  }
}

